import requests

from common.config import cmslogin, getconf

import json
class MetaDataManage:
    def getSelectProjectList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getSelectProjectList"
        header={"Content-Type": "application/json;charset=UTF-8"}
        data={"projectName":""}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('项目列表',r.json())
        return r.json()

    def getDbNameList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getDbNameList"
        header={"Content-Type": "application/json;charset=UTF-8"}
        r=requests.post(url,headers=header)
        #print('数据库列表',r.json())
        return r.json()

    def getMyBrowseList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getMyBrowseList"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        r=requests.post(url,headers=header)
        #print('浏览记录',r.json())
        return r.json()

    def getMyCollectionList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getMyCollectionList"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"current":1,"size":15}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('我的收藏',r.json())
        return r.json()

    def getTableList(self,env,queryType,queryStr):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getTableList"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"current":1,"size":12,"queryStr":queryStr,"queryType":queryType}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('搜索',r.json())
        #print(token)
        return r.json()

    def saveMyCollection(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/saveMyCollection"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('收藏',r.json())
        return r.json()

    def cancelMyCollection(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/cancelMyCollection"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('取消收藏',r.json())
        return r.json()

    def getTableBasicInfo(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getTableBasicInfo"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('表基本信息',r.json())
        return r.json()

    def getFieldInfoList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getFieldInfoList"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('表字段信息',r.json())
        return r.json()

    def getTableSql(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getTableSql"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('表SQL',r.json())
        return r.json()

    def getTableDemoList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getTableDemoList"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('数据示例',r.json())
        return r.json()

    def getTableStatisticsList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getTableStatisticsList"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('统计趋势',r.json())
        return r.json()

    def getTableCreateSql(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/metadata/getTableCreateSql"
        token = cmslogin(env)
        header = {"Content-Type": "application/json;charset=UTF-8", "token": token}
        data={"tableId":67}
        r=requests.post(url,data=json.dumps(data),headers=header)
        #print('建表语句',r.json())
        return r.json()


#a=MetaDataManage()
#a.getTableCreateSql('test')

